﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace pygs.Classes
{
    public class DegreesMinutesSeconds
    {

        bool isPositive;
        public bool IsPositive
        {
            get { return isPositive; }
        }

        uint degrees;
        public uint Degrees
        {
            get { return degrees; }
        }

        uint minutes;
        public uint Minutes
        {
            get { return minutes; }
        }

        double seconds;
        public double Seconds
        {
            get { return seconds; }
        }

        public DegreesMinutesSeconds(double decimalDegrees)
        {
            isPositive = (decimalDegrees > 0);
            degrees = (uint)Math.Abs(decimalDegrees);
            double doubleMinutes = (Math.Abs(decimalDegrees) - Math.Abs((double)degrees)) * 60.0;
            minutes = (uint)doubleMinutes;
            seconds = (doubleMinutes - (double)minutes) * 60.0;
        }

        public DegreesMinutesSeconds(bool isPositive, uint degrees, uint minutes, double seconds)
        {
            this.isPositive = isPositive;
            this.degrees = degrees;
            this.minutes = minutes;
            this.seconds = seconds;
        }

        public double ToDecimalDegrees()
        {
            double val = (double)degrees + ((double)minutes / 60.0) + ((double)seconds / 3600.0);
            val = isPositive ? val : val * -1;
            return val;
        }

        public override string ToString()
        {
            return degrees + "d " + minutes + "' " + seconds + "\"";
        }
    }

    public class Location
    {
        public DateTime Time { get; set; }
        public float Speed { get; set; }
        public float EllipsoidAltitude { get; set; }
        public float SeaLevelAltitude { get; set; }
        public double Latitude { get; set; }
        public DegreesMinutesSeconds LatitudeAsDegreesMinutesSeconds { get { return new DegreesMinutesSeconds(Latitude); } }
        public double Longitude { get; set; }
        public DegreesMinutesSeconds LongitudeAsDegreesMinutesSeconds { get { return new DegreesMinutesSeconds(Longitude); } }
        public float Heading { get; set; }

        public override string ToString()
        {
            return string.Format("Time: {0}; Speed: {1}; Latitude: {2}; Longitude: {3}; Heading: {4}", 
                new Object[] { Time, Speed, LatitudeAsDegreesMinutesSeconds, LongitudeAsDegreesMinutesSeconds, Heading } );
            
        }
    }
}
